package com.hctforgreen.greenservice.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.hctforgreen.greenservice.R;

/**
 * theme setting 存储Util
 * 
 * @author Tallen Zhai
 * 
 */
public class ThemeStoreUtil {

	public static void saveSkinId(Activity activity, String sSkinId) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.THEME_SETTING_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		Editor editor = sharedPreferences.edit();

		editor.putString(HctConstants.THEME_SETTING_STORE_KEY_VALUE, sSkinId);
		editor.commit();
	}

	public static void saveSkinFilePath(Activity activity, String path) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.THEME_SETTING_FILE_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		Editor editor = sharedPreferences.edit();

		editor.putString(HctConstants.THEME_SETTING_FILE_STORE_KEY_VALUE, path);
		editor.commit();
	}

	public static String getSkinFilePath(Activity activity) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.THEME_SETTING_FILE_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		String path = sharedPreferences.getString(
				HctConstants.THEME_SETTING_FILE_STORE_KEY_VALUE, "");
		return path;
	}

	public static int getSkinId(Activity activity) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.THEME_SETTING_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		String sSkinId = sharedPreferences.getString(
				HctConstants.THEME_SETTING_STORE_KEY_VALUE,
				"R.drawable.ic_default_activity_bg");
		int skinId = R.drawable.ic_default_activity_bg;
		if (sSkinId.equals("R.drawable.ic_default_activity_bg")) {
			skinId = R.drawable.ic_default_activity_bg;
		} else if (sSkinId.equals("R.drawable.ic_skin_2_bg")) {
			skinId = R.drawable.ic_skin_2_bg;
		} else if (sSkinId.equals("R.drawable.ic_skin_3_bg")) {
			skinId = R.drawable.ic_skin_3_bg;
		} else if (sSkinId.equals("R.drawable.ic_skin_4_bg")) {
			skinId = R.drawable.ic_skin_4_bg;
		} else if (sSkinId.equals("R.drawable.ic_skin_5_bg")) {
			skinId = R.drawable.ic_skin_5_bg;
		} else if (sSkinId.equals("native_file")) {// 自定义背景
			skinId = -1;
		}
		return skinId;
	}

	public static int getItemLayoutSkinId(Activity activity) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.THEME_SETTING_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		String sSkinId = sharedPreferences.getString(
				HctConstants.THEME_SETTING_STORE_KEY_VALUE,
				"R.drawable.ic_default_activity_bg");
		int skinId = R.drawable.lyt_skin_1_item_bg;
		if (sSkinId.equals("R.drawable.ic_default_activity_bg")) {
			skinId = R.drawable.lyt_skin_1_item_bg;
		} else if (sSkinId.equals("R.drawable.ic_skin_2_bg")) {
			skinId = R.drawable.lyt_skin_2_item_bg;
		} else if (sSkinId.equals("R.drawable.ic_skin_3_bg")) {
			skinId = R.drawable.lyt_skin_3_item_bg;
		} else if (sSkinId.equals("R.drawable.ic_skin_4_bg")) {
			skinId = R.drawable.lyt_skin_4_item_bg;
		} else if (sSkinId.equals("R.drawable.ic_skin_5_bg")) {
			skinId = R.drawable.lyt_skin_5_item_bg;
		}
		return skinId;
	}

}
